package net.minecraft.src;

import java.util.HashMap;
import java.util.Map;

public class RecipesGrinder
{
	private static RecipesGrinder manager = new RecipesGrinder();
	private static Map<Integer, ItemStack> itemList;
	private static Map<Integer, HashMap<Integer, ItemStack>> combinedList;
	
	private RecipesGrinder()
	{
		itemList = new HashMap<Integer, ItemStack>();
		combinedList = new HashMap<Integer, HashMap<Integer, ItemStack>>();
		addRecipe(mod_pph.algaeItem.shiftedIndex, new ItemStack(Item.dyePowder, 2, 10));
		addRecipe(mod_pph.brachiopodShell.shiftedIndex, new ItemStack(mod_pph.shellPowder, 4));
		addRecipe(mod_pph.ammoniteShell.shiftedIndex, new ItemStack(mod_pph.shellPowder, 4));
		addCombinedRecipe(mod_pph.algaeItem.shiftedIndex, mod_pph.shellPowder.shiftedIndex, new ItemStack(mod_pph.algae, 1, 3));
	}
	
	private void addRecipe(int itemId, ItemStack result)
	{
		itemList.put(itemId, result);
	}
	
	private void addCombinedRecipe(int itemId, int itemId2, ItemStack result)
	{
		addCombinedRecipe(itemId, itemId2, result, true);
	}
	
	private void addCombinedRecipe(int itemId, int itemId2, ItemStack result, boolean doFlipped)
	{
		HashMap<Integer, ItemStack> list = combinedList.get(itemId);
		if(list != null)
		{
			list.put(itemId2, result);
			combinedList.put(itemId, list);
		}
		else
		{
			HashMap<Integer, ItemStack> newlist = new HashMap<Integer, ItemStack>();
			newlist.put(itemId2, result);
			combinedList.put(itemId, newlist);
		}
		if(doFlipped)
			addCombinedRecipe(itemId2, itemId, result, false);
	}
	
	public static RecipesGrinder getGrinder()
	{
		return manager;
	}
	
	public ItemStack getSingleResult(int itemId)
	{
		ItemStack result = itemList.get(itemId);
		if(result == null)
			return null;
		return result;
	}
	
	public ItemStack getCombinedResult(int itemId, int itemId2)
	{
		HashMap<Integer, ItemStack> combineMap = combinedList.get(itemId);
		if(combineMap == null)
			return null;
		ItemStack result = combineMap.get(itemId2);
		if(result == null)
			return null;
		return result;
	}
}